logging and some cleanup