Updates to_code method so it can also cover nested trees or range values. Adds a new test to spec