Fixed code comments and added some checks. Tests have not been updated.