Added setup
More changes to code and error handling