finally compiles and is closed to finished, now it needs debugging of the callbacks