Pretty error output
A lot of many fixes, statemachine, but he doesn't work,

Fixed memory leaks.