works now also for vector, tensor3 and tensor4 and for more than 2 inputs + corrected memory bugs
merge