First commit of rivet code, needs cleaning up