Fixes #1560 - Type-safety added to two places to prevent crashes