Refractoring the code to have more fns

Read state and post json functions