merged Warren's Code but still some small problems to fix