Refactor some of the source code