Some warnings fixed
Some more optimizations
Start backporting files from newer version