Some very dirty bug fixing