cleaned up ruby pseudocode