Added wifi check and exception handling