code fixes & refactoring