Performance improvements; also some hardening on the user input