tidied code a little bit