Finalized exception handling and added output options: HTML vs JSON