Refactor recommendation code