Refactored code and added interactive mode