has minor fixes and some rearranging of functions.
just a minor indexing adjustment
more minor fixes. should work now.