compiling and almost working
fix some bugs