fixed for Rails 4 and also fixed some minor issues here and there