Refactoring to make things more beautiful.
Removed static vars.
Started working on protocol.