Various code cleanups and removing some unused APIs.