updated and tidied up