warnings and variable scope

Hi @andressobral, this is my last commit for now. I enabled some warnings in the CMakelists.txt, you may include this or not.
I still see one mem leak in the static code analysis, but I need to dive deeper in the code to see if it is really a problem.
Thanks for merging my stuff so far.