Added connection error handling and fixed a rounding error