added better endpoint handling