changed conditional code to be more ruby-like