Add cmd line argument to server and do some cleanup
Refactor a lot of things and improve logging