some minor renaming and code movement around table locking to make it easier for me to follow the code