Pull in refactoring from simple version