Refactor: code cleanups, refactoring