ugly error check