Refactor to remove Rails dependency.