akmost finished. need to remove some comments etc.