more refactoring and formating