Code cleanup

Fixed most of the warnings and build problems