Based on tutorial from Ruby on Rails tutorial second edition book