Followed David's advice for cleaning up code