Refactor stack scanner