performance improvement to ruby script.