Added commenting and error messages