Refactor some code methods