Fix a few bugs found while testing with rails