added comments and credit to Tom J Nowell