Refactored LIBKH functiuns

I just refactored many functiuns of LIBKH, reorganized and cleaned up a
little bit the code. Should be easier to use it now