Refactored using Command design pattern