Fix for relative URLs not working sometimes

Rebased #16 against master