Refactor to clean up implementation code.