Added locking and simplified modules