Slightly tidied up code