Better logging and rewrite of main server loop!