handle empty results
clean up and refactor