refactoring and fixes after testing