Fix most of the warnings and some minor problems