refactored robot solution