Increased portability

Removed CLS system calls from code.
Added classes for state machine and state manager

NOTE: Currently not working, the problem seems to be in the
StateManager header file.