Refactored code placing logic