split and tidied the code a bit