new framework and tidied up code