Remove redundant debug flag and add input flag to simplify code
Add input checking