Fix to get working on Rails 4

Maybe refactoring for perfomance?