Fixed errors in logging and saving