refactor all

so many problems in previous code, so refactor it