ProcessCommand method in Engine.cs refactored