Version 2.0 - fixed bugs and fleshed out explanations; m is used as variable name instead of n because n is useful in debugging