Clean up and refactor flattening expressions

This is a simpler version of the flattening expressions pass, but it
still has issues with handling condition nodes, which we need to deal
with some how.
Rewrite the final pass, av; resolves #62