Bring general sketch commits upstream

Move the general parts of PR #1178 upstream decrease the maintenance work.
How about using uint64_t instead of long unsigned? Could make the data size more obvious.