added multi notebook functionality and lots of tidying up