fix crash on error, fix issue when using non-standard port