refacoring function select