Huge code refactoring, separation of functions that deal with joins and uppercasing, checked variable names etc. Tests pass, but will need more testing