Improving rails implementation