replaced unnecessary mallocs with arrays