Fixed some bugs, not sure about defined class stuff and may be some
minor bugs