A better impelementation by 2 level pointer
refine the code