Heavy refactorings, test madness

Rewrote chain functionality, made it so it would be possible to directly trigger other functions from chains.
Major refactorings for Z core