First version, at least partially working