added more casts and fixed formatting