Added main loop

Added main loop.
Added small test for main loop.
Added docs.