Refactor for rails independent usage. Resolves #1.