Added comments and function details to original stub provided. Tested and confirmed working.