Changed Code with help of Paul