Fix for #148 and possibly #149 plus a few code polishes here and there