Refactor to remove layering violations. #1170