Added explicit casts to allow for compilation under -pedantic