Tidied up into functions.