refactored code and organized files