fix some bugs due to missing casts