check if reach the end