got quite far, still not working entirely