clean up logging and logic a bit