Clean up Setting, Window handling - fix some potential NPE cases.