Tidied up some key functions.