Fix a ownership bug (thanks to cantora)
fix upcasting problem (#77 thanks to cantora)