Code refactored based on Staples

Code refactored based on Staples