Fixes, refactoring