Moved implementation into it's own class file. Added comments throughout. Cleaned up locking.