finish the endpoint recognition algorithm
format the code in whole project