Smoothness of invariant densities for certain classes of dynamical systems