Added comments and fixed some errors