modularized the code and reorganized files