Condense modal hiding logic, fixes #1159