Implementing a few fixes suggested by miekg