minor refactoring & fix