main is mostly working