I fixed a bug with in the theta function, still needs more improvement