Refactor program validation