some bugs and compiler errors fixed