refactored threading, locks added
config scheme