this code closes #6