new version mostly working