Complete endX function