fix ownership errors
fix type shadowing warnings