Preparing to generalize sampling

Introducing a generic stacking function that can stack position and
feature space together. Some optimizations based on template meta info.