refactoring + minor changes