Started to refactor the original code. Refs #9358