fix and refactor clean ruby code