Needs a bit of cleaning up but almost done