clean and refactor some code for cleaner