Serialization improvements based on FSM in issue #1

Involves dartcoin/dartcoin-lib#1
Script improvements
Readability and efficiency improvements