refactored module to avoid deadlocks