moved state to the last parameter - following gen-server et al.