Refactor some parts of code.