fixing some code for zero-length arrays