Prevent memory leak
Making createQuerySocket more sane
Changing error message
Better way of checking if socket is valid