Refactor function to use JSON style