improve ruby code