WIP commit, bug 1062558

@guilherme-pg Here's a sketch of a solution for bug 1062558. Does this seem sane?