Fixes to list_foreach, and testing function