refactor alignment validity checking