tidied up the code a little
merged some code tidy-ups