Refactoring, fixes, improvements