Fix URL trimming

Closes #397