add exception handling at input, and refactor dinda's portion of codes for a better modularization