Rearranging functions in lib and klib after merge from Phil