Tidy logging
Code cleanup, extract some vars