clean up code and reorganize files