More fixes & refactoring