debugged javascript errors - added null check