Initial port of old codebase

Accidently used older version of the old codebase so needs much work.