runtime: refactor code for dereferencing pointers