added better end handling