some basic ports of things from mecode