Move foreach logic to runtime
Add traversable check