Refactored: table formating, json forming