Merge pull request #75 from srgpqt/master

replace some raw sql with database-agnostic activerecord queries