Add test cases, fix magic square checking