code refactoring and create scatter block