Too many changes

Tests. Restructure Main.scala for better testing. Fix bug in range
unfolding.