refactoring and styling fixes