cleaned added comments and several bug fixes