fixed a lot of the bugs produced earlier