Added better error messages for connection errors. Fixed $nin bug