total overhaul

Script almost entirely rewritten with a more accurate scoring algorithm.
Code optimized and shortened.