Ensure functionality of three and two variables.

 * Fix bugs when generating code for three or two variables.
 * Add tests for three and two variables.
 * Made generate_cube function simpler and slightly easier to follow.