These two dynamic castings could raise InvalidCaseException. Might be good idea to wrap them in try/with and process `null` case.