Duplicate code alert - anyway to refactor this so it's not duplicated in app.js?