Cleaned up and rubyfied the code.