just about done
purify
fix logical functions