Version 6 with slight modifications and tidying