Add tests to ensure exceptions are flung and fixed wrong variable name used