Added comments and bug fixes