more refactoring & fixes