cleaned up reused code to parse json