Some more groundwork
First fully working version