This needs some general exception handling too I think. If anything here throws an exception it should be handled nicely.