Move hash function to controllers where it might be useful (particularly for APIs). Made hash function a helper method so it can still be used in views.