tidied up the code a tiny bit
still tidying