Prevent double registering and clean useless cast

Signed-off-by: Miia Leinonen <miia.leinonen@oss.tieto.com>