Fix crash introduced in recent commit

This reverts parts of 61681532a2afbdeb47e68ace53d96ee5b75bf706.