cleaned up command loop