Fix a nasty bug reported by @jip

Basically, I typecasted a wrong object to a wrong type...