Set a proper timeout and moved urlhandling to a separate function