fixing "0 of undefined" error