Major code refactoring, main loop.
Merge pull request #2 from baspeters93/dev

Major code refactoring, main loop.