Fixed undefined classes

Still some bugs, but does work quite ok