Fix hangs

Not the best way of doing this but at least it works.