Lot of bug fixes and improvements