Change sum() to flatten().  Include stdlib.