cleaned and organized code for refactoring