cleaned up code. computed simple hysterisis loop