tidied code a little