added balanced insert code; have not tested it yet