Working copy

Needs testing and tiding of code