cleaned up code, fixed valid_url