use const more consistently (fixes an actual bug) and remove unneeded casts