Fix up buggy code