Cleaned up ruby code