Add end-state detection and functionality