Fix some Findbugs and IDE issues, refactor some duplicated code, improve some exception texts, add comment for missing Ptg for SxName