improved the script a bit