fixed 'cannot access 'name' of undefined' error
removed some redundancies