Reworked the datapath to have functions and temporary blocks.
Removed a few tmp variables we don't need.