add casting and remove unnecessary allocation