started refactoring and formatting

started refactoring and formatting