refactor for rails 4