Move type stack handling to a new class