Re-organisation

Reorganised code so it works.