Fix some bugs and increase efficiency.

Change to only find three biggest numbers instead of sorting whole
array.