Added some comments and fixed a few errors