Generalize code and make directory structure