Now works correctly for multiple instances