More logging and some bugs fixed