revert optimisation
add sanity check
minor gui fixes