fix select bug, but not perfect soln