Refactor some ruby code.