Refactored handshake and message processing

Incomplete, will not run!
Finished refactoring
Merge pull request #1 from DaveRandom/refactoring

Refactoring