Massive bug fixes