refactor jsonhandler + errorhandler