First version that actually comes close to working