Deferred calculation

This branch primarily focuses on deferred calculation, but also includes some major refactoring of existing code to make it easier to support the deferred calculation approach as well as some bugfixes that made more sense to apply on the branch code.