Cleaned up the script. More efficient and simpler.