Fix most outstanding bugs