Decode percent-encoding in url. Add test. Reorder code.