tighten up url resolution and handle edgecases