Added comments, minor coding fixes