Fixed null pointer exception bug in enhanced loop