refactored; shorter, more Ruby-like