optimized and debuged mutithreading... moved locks to their own class