webtest cleanup and code improvement(using helper function)