optimzed and cleanedup autoinvoicing