code mostly working