implemented subroutine traversal function

barely tested, but might be working