Add constructor and improve safety