refactored to accept json