fixes #1011 #1012 #1013 #1038