Simplified code

still the same running time (15 seconds on intel core i5 1.7ghz laptop)