refactoring and fixing minor issues