added loads of stuff, inc error handling