cleaned up code with helper class