add in the simplified version from Wei's code.
will do interfacing after this