Fix form detection and login page closing