TODO: rewrite constants, improve expandNode()