fixed max_end bug