refactored with Alex's suggestion