Actually mostly working code