fix issue 17
fix possible deadlock
removal of debug code
fix issue 16