Better logging and some cleanup