started mutex lock
refactoring
first semi-stable version