forked and upgraded to use with rails 4