Tidied code up a bit