Improve error message, plug memory leak and simplify code
Improve error message, plug memory leak and simplify code

khorben/pkg,junovitch/pkg,khorben/pkg,Open343/pkg,junovitch/pkg,en90/pkg,khorben/pkg,skoef/pkg,Open343/pkg,skoef/pkg,en90/pkg