Full integration code, compiles but untested