some light refactoring and formatting