cleaned up with a helper function.