Minor cleanups and renamed some functions.