Implemented much more locking and finally updated comments to reflect actual code.