Refactor to clean up source code