Cleanup and locking fixes. don't ask. don't tell :)