Fixed some bugs, now it compiles and works