added a helper function and some comments