enhanced patch script a bit to prevent errors