OK,Re-written the code according to your suggestion. new patch: