Replaced the urldecode function from ThomasH (Stack Overflow) with a
working one.
Removed some debug output.
Fixed an invalid memory access caused by a to small buffer.
Fixed iteration code to allow safe removal of buffers in the chain.