Cleanup of this script, works great now.