Converted string to int before storing data.
Splitted request processing and json printing. Also set correct header
before printing ('Content-type: application/json').