overall refactor, add json output