function KSM with gui