Ported over all functionality, not tested.