changed the code to use masks instead of square ids consistently