loads of stuff

fix memory problems
switches are a bit closer to working