flat-selector refactoring and bug fixing