Changed casts to follows STLs suggestion