a bit of refactoring & cleanup