Slightly simplify some code in sem_check_map
Fix crash opening a file inside a procedure