Implemented proper error handling thanks to xdissent_ @ freenode