Fixing small javascript var undefined error