Refactor code to separate pieces.