refactoring and some styling