moved sleep above to sleep if connection is refused as well