refactored more ruby code