Created helper function and added some comments