Added some comments and afew bugs