Typecasting and bugfix