Fix Tosdr not working on startup

Also doing some cleanup, style fixes and readability stuff. and don't
expect the world to be better now.