WIP. Base implementation. Not yet completely functional.