Added state monad
Moved function definitions out of constructor