Refactor and fix mapfile validation.