Massive code improvements