Cap scrolling to the right end
Added some comments about binarySearch function
Refactored a bit