Here is my updated code reflecting Max's feedback