Fix #2090, #2009, #2007, #1945, #536, #1090