Refactored to use context managers
Added ability to read commands from a file