Miscellaneous improvements in logic and warnings