Bugfixes
Code factoring
Sleep in main loop