Refactored to simplify - Jeremy Kerr