Minor fixes
Small fixes and refactoring