Fix several warnings and bad practices in the code