Refactored last merge. Closes #3321