made the script a bit smarter