optimize KSM functions by voku