Fix compilation warnings and code clean up