Implementing the auto-rotate feature