mostly working finite code