Improve logger, fix bugs