Tidied up a function.