Added STDIN controls, and refactored into multiple files