Fix typos
Use intermediate variables instead of many casts