improved indentation, added exeption when not all inputs have the same ndims, tried to improve some memory / reference counting issues, removed initialisation of variable sized arrays, which causes problems under windows