Help me debug this JavaScript code that's throwing a null reference error.