Added some extra checks for debugging.