Some fixes to reflection stuff

@jeffdyer, can you look at c174547 to make sure that's ok?

More importantly, as it's a pretty fundamental change, @mbebenita, can you look at  	13a0a14?