fixed programmatic usage example and added some cleanup