Refactored code to be used programmatically
Added example file