Added some comments and error verification