Fixed bad variable and typecasting