Modified code to solve serialization issue