Fix tests and some compilation problems