Fix initialization and dat ahandling issues