Refactor to use json