move $max_tiles to a single point and fix edge cases in ui