Minor fixes & refactoring