Adding the main code, with updated documentation comments