New and improved script that works better