refactored selects, fixed tests