Improved test code and added comments to important areas of the code