Refactoring & fixes