refactor instances handler