Update rails and minor refactoring