Code refactoring, cleanup and improvements. Rails 4.2 support