Moved state and fixed a few of the errors

still more errors remain.