Fix warnings and misc code cleanup