Fixes for 1044 and 1047

fixes #1044
fixes #1047 with @emanuele45 review since that function is his baby
Also fixes footnote issue reported on site by @IchBin