Mostly working code
fully working