change spawn to thread in gen_server:cast