fixed logging and several other bugs