move more duplicate code to function library

On branch master
Changes to be committed:

	modified:   lib/km.lib