refactoring and indentation fixing