Small refactoring. Still have problems of concurrency.