refactoring due to inspection + bug fixes