refactored with Tommys suggestions