added logging, fixed small bug, no mutex on logging yet