Partially working core glue code. Needs debugging.