refactored. added program-checking