reworked formed(balanced) function and look up function