Tidied up code as discussed.