Minor refactoring & fixes