Added malloc() to allocate memory to state pointer