bugs fixed, compiles and works