Bugfix: array can contain zero elements, so we needed to check for that