refactoring ruby code into rectifier