Improve code, replace while to for, remove don't use function
Improve code