Added Javadoc style comments to all functions, plus some comments within the functions