null termination fix + close connection