moved state to process funtion