some code re-write