added logging
fixed locking