made adjustments to main script to ease its use as a daemon