fixed most of the bugs with this I think. Something seems to go wrong though on test 53.