Added some comments to the function .. should really be in a test