it may all be working now -- needs testing and tidying