Resolve many warnings and some code cleanup