adding functions to code and reformatting json