Updated the code for multiple instances