Add more checks, remove debug code.