refactoring
added mutex for sync