bug fix and refactor
Merge remote-tracking branch 'ray/master'

Conflicts:
	kos.c