Refactor and fix interop bugs