Updated documentation with function control flow explanation