Better logging and bug fixes