updated the code with schema to make it more generic