refactored get next recommendation to shift logic into SQL query