possible fix to end condition