Reorganize code
Implement pre-compilation of case alternatives.

Doesn't work as expected, probably heap usage is computed incorrectly