Fixed logging and some minor bugs.